<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .goods {
            width: 100%;
            margin-top: 0;
        }

        .goods img {
            width: 100%;
        }
    </style>
</head>

<body>
    <div id="root">

    </div>
</body>
<script src="./react.js"></script>
<script src="./react-dom.js"></script>
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script type="text/babel">
    class App extends React.Component {
        state = {
            goodsList: [],
            hotList:[]
        }
        render() {
            return (
                <div>
                    <div>
                        <button onClick={() => this.getDataList()}>获取商品列表</button>
                    </div>
                    <div>
                        {
                            this.state.goodsList.map((item, index) => {
                                return <Goods key={index}  goods={item} />
                            })
                        }
                    </div>
                    <button onClick={()=>this.getHotList()}>获取热门推荐</button>
                    <div>
                        {
                            this.state.hotList.map((item,index)=>{
                                return <Goods key={index} goods={item}/>
                            })
                        }

                    </div>
                </div>
            )
        }
        getDataList() {
            let that = this;
            $.ajax({
                url: "https://apif.java.crmeb.net/api/front/product/leaderboard",
                method: "get",
                dataType: "json",
                success(res) {
                    console.log(res)
                    that.setState({
                        goodsList: res.data
                    })
                }
            })
        }
        getHotList(){
            $.ajax({
                url:"https://apif.java.crmeb.net/api/front/index/product/1/?page=1&limit=10",
                method:"get",
                dataType:'json',
                success:(res)=>{
                    console.log(res)
                    this.setState({
                        hotList:res.data.list
                    })
                }
            })
        }
    }
    class Goods extends React.Component {
        render() {
            return (
                <div className='goods'>
                    <img src={this.props.goods.image} alt="" />
                    <p>{this.props.goods.storeName}</p>
                    <p>{this.props.goods.price}</p>
                </div>
            )
        }
    }
    ReactDOM.render(<App />, document.getElementById("root"))
</script>

</html>